import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    Map<String, Integer> foodRate;
    // 烹饪方式 食物列表
    Map<String, List<String>> cuisineFoods;
    public void FoodRatings(String[] foods, String[] cuisines, int[] ratings) {
        foodRate = new HashMap<>();
        cuisineFoods = new HashMap<>();
        for (int i = 0; i < foods.length; i++) {
            foodRate.put(foods[i], ratings[i]);
            if (cuisineFoods.containsKey(cuisines[i])) {
                cuisineFoods.get(cuisines[i]).add(foods[i]);
            }else {
                List<String> list = new ArrayList<>();
                list.add(foods[i]);
                cuisineFoods.put(cuisines[i], list);
            }
        }
    }

    public void changeRating(String food, int newRating) {
        foodRate.put(food, newRating);
    }

    public String highestRated(String cuisine) {
        List<String> list = cuisineFoods.get(cuisine);
        return list.stream().sorted((a, b) -> {
            Integer a1 = foodRate.get(a);
            Integer b1 = foodRate.get(b);
            if (a1 == b1) {
                return a.compareTo(b);
            }
            return b1 - a1;
        }).findFirst().get();
    }
}
